//Serach模块的小仓库
import { getGetSerachInfo } from '@/api'

const state = {
  serachList: {},
}
const mutations = {
  GETSERACHINFO(state, value) {
    state.serachList = value
  },
}
const actions = {
  //获取serach信息
  async getSerachInfo(context, params = {}) {
    //params至少是一个空对象
    const result = await getGetSerachInfo(params)
    if (result && result.code == 200) {
      context.commit('GETSERACHINFO', result.data)
    }
  },
}
//计算属性，为了简化数据 至少给一个初始值
const getters = {
  goodsList(state) {
    return state.serachList.goodsList || []
  },
  trademarkList(state) {
    return state.serachList.trademarkList || []
  },
  attrsList(state) {
    return state.serachList.attrsList || []
  },
  pageSize(state) {
    return state.serachList.pageSize || []
  },
  pageNo(state) {
    return state.serachList.pageNo || []
  },
  total(state) {
    return state.serachList.total || []
  },
  totalPages(state) {
    return state.serachList.totalPages || []
  },
}

export default {
  namespaced: 'serach',
  state,
  mutations,
  actions,
  getters,
}
